part of '../widgets.dart';

class VanSwitch extends StatelessWidget {
  /// props - 开关选中状态(默认: false)
  final bool? value;

  /// props -
  final Ref<bool>? controller;

  /// props - 是否为加载状态(默认: false)
  final bool loading;

  /// props - 是否为禁用状态(默认: false)
  final bool disabled;

  /// props - 开关按钮的尺寸，默认单位为 px(默认: 26)
  final double? size;

  /// props - 打开时的背景色(默认: #1989fa)
  final Color? activeColor;

  /// props - 关闭时的背景色(默认: rgba(120, 120, 128, 0.16))
  final Color? inactiveColor;

  /// props - 打开时对应的值(默认: true)
  final dynamic activeValue;

  /// props - 关闭时对应的值(默认: false)
  final dynamic inactiveValue;

  final VanSwitchStyle? style;

  const VanSwitch({
    super.key,
    this.value,
    this.controller,
    this.loading = false,
    this.disabled = false,
    this.size,
    this.activeColor,
    this.inactiveColor,
    this.activeValue = true,
    this.inactiveValue = false,
    this.style,
  });

  VanSwitchStyle getComputedStyle(BuildContext context) {
    if (style?.isNonNull == true) return style!;
    double? size = style?.size;
    double? width = style?.width;
    double? height = style?.height;
    double? nodeSize = style?.nodeSize;
    VanBgColor? nodeBackground = style?.nodeBackground;
    String? nodeShadow = style?.nodeShadow;
    VanBgColor? background = style?.background;
    VanBgColor? onBackground = style?.onBackground;
    double? duration = style?.duration;
    double? opacity = style?.opacity;

    size ??= kVanSwitchSize.toDouble(context);
    width ??= kVanSwitchWidth.toDouble(context);
    height ??= kVanSwitchHeight.toDouble(context);
    nodeSize ??= kVanSwitchNodeSize.toDouble(context);
    nodeBackground ??= kVanSwitchNodeBackground.toBgColor(context);
    nodeShadow ??= kVanSwitchNodeShadow.get(context);
    background ??= kVanSwitchBackground.toBgColor(context);
    onBackground ??= kVanSwitchOnBackground.toBgColor(context);
    duration ??= kVanSwitchDuration.toDouble(context);

    if (disabled) {
      opacity ??= kVanSwitchDisabledOpacity.toDouble(context);
    }

    return VanSwitchStyle(
      size: size,
      width: width,
      height: height,
      nodeSize: nodeSize,
      nodeBackground: nodeBackground,
      nodeShadow: nodeShadow,
      background: background,
      onBackground: onBackground,
      duration: duration,
      opacity: opacity,
    );
  }

  @override
  Widget build(BuildContext context) {
    return const Text("未开发");
  }
}
